<?php
require_once("Connections/conn_admin.php");
mysql_select_db($database_conn_admin);

$queryJumStaf = sprintf("select distinct count(id) as bil, noic from maklumat_staf");
$rsJumStaf = mysql_query($queryJumStaf)or die(mysql_error());
$rowJumStaf = mysql_fetch_assoc($rsJumStaf);
$jumStaf = $rowJumStaf['bil'];
//
//$query7lebih = sprintf("select noic, bil_hari as bil from permohonan_kursus " .
//		"" .
//		"");
//$rs7lebih = mysql_query($query7lebih)or die(mysql_error());
//$row7lebih = mysql_fetch_assoc($rs7lebih);
//$totalRowc=mysql_num_rows($rs7lebih);
//echo $lebih = $row7lebih['bil'];
//
//echo $query7kurang = sprintf("select noic from permohonan_kursus " .
//		"group by noic");
//$rs7kurang = mysql_query($query7kurang)or die(mysql_error());
//$row7kurang = mysql_fetch_assoc($rs7kurang);
//$totalRowc=mysql_num_rows($rs7kurang);
//$kurang = $row7kurang['bil'];
$thn = date('Y', time());
//$thn = 2012;
//echo 'tahun: '.$thn.'<br/>';
$jabatRep = "Bagi Semua Jabatan, ";
$thnRep =  "Tahun ".$thn;
$tajukRep = "Laporan ";
$where = " and year(k.tarikh_mula) = $thn";
$group = "group by noic";

//cari
if(isset($_POST['cari'])){
    foreach ($_POST as $key => $val){
        $$key = mysql_real_escape_string($val);
    }
    if(!empty($tarikh_mula))
        $tarikh_mula = date('Y-m-d', strtotime($tarikh_mula));
    if(!empty($tarikh_tamat))
        $tarikh_tamat = date('Y-m-d', strtotime($tarikh_tamat));
    
    if(!empty($jabatan) && !empty($tarikh_mula) && !empty($tarikh_tamat)){
        $jabatRep = "Bagi ".$jabatan.", ";
        $thnRep = date('d F Y', strtotime($tarikh_mula))." - ".date('d F Y', strtotime($tarikh_tamat));
        $where = " and nama_jabatan = '$jabatan' and k.tarikh_mula between '$tarikh_mula' and '$tarikh_tamat'";
    }
    if(!empty($jabatan) && (empty($tarikh_mula) || empty($tarikh_tamat))){
        $jabatRep = "Bagi ".$jabatan.", ";
        $where = " and nama_jabatan = '$jabatan'";
    }
    if(empty($jabatan) && !empty($tarikh_mula) && !empty($tarikh_tamat)){
        $thnRep = date('d F Y', strtotime($tarikh_mula))." - ".date('d F Y', strtotime($tarikh_tamat));
        $where = " and k.tarikh_mula between '$tarikh_mula' and '$tarikh_tamat'";
    }
}
$tajukRep .= $jabatRep.$thnRep;
$queryxp = sprintf("select distinct m.noic, m.nama, sum(k.bil_hari) as hari from permohonan_kursus k 
    inner join maklumat_staf m on k.id = m.id 
    where 1 %s %s",
        $where,
        $group
		);
$rsxp = mysql_query($queryxp)or die(mysql_error());
$rowxp = mysql_fetch_assoc($rsxp);
$totalRomxp = mysql_num_rows($rsxp);
//$jumstaf = 0;
$lebihsama7 = 0;
$kurang7 = 0;
$xplansung = 0;
do{
    //$jumstaf++;
    if($rowxp['hari']>=7){
        $lebihsama7 +=1;
    }elseif($rowxp['hari']<7 && $rowxp['hari']>0){
        $kurang7 +=1;
    }else{
        $xplansung +=1;
    }    
}while($rowxp = mysql_fetch_assoc($rsxp));
$xp = $jumStaf - $lebihsama7 - $kurang7;
//    echo $jumStaf.' $jumStaf<br/>';
//    echo $lebihsama7.' $lebihsama7<br/>';
//    echo $kurang7.' $kurang7<br/>';
//    echo $xp.' $xp<br/>';
//    echo $xplansung.' $xplansung</br>';
    
/*$queryReport = sprintf("select sum(bil_hari) as hari, count(noic) as bil, nama, noic from permohonan_kursus " .
		"");
$rsReport = mysql_query($queryReport)or die(mysql_error());
$rowReport = mysql_fetch_assoc($rsReport);*/

?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta charset="utf-8" />
	<link rel="icon" type="image/png" href="favicon.ico" />
	<link rel="apple-touch-icon" href="touch-icon.png" />
	
	<title>Maklumat Kursus</title>
	
	<!--== BEGIN STYLES ==-->
	<link rel="stylesheet" href="css/config.css" />
	<link href="../stafs/css/jquery-ui-1.9.1.custom.min-2.css" rel="stylesheet" />
	<!--[if IE 7]> <link rel="stylesheet" href="css/ie7.css" /> <![endif]-->
	<!--[if IE 8]> <link rel="stylesheet" href="css/ie8.css" /> <![endif]-->
	<!--[if IE 9]> <link rel="stylesheet" href="css/ie9.css" /> <![endif]-->
        
<!--        jqplot-->
        <link class="include" rel="stylesheet" type="text/css" href="jplot/jquery.jqplot.min.css" />
        <link rel="stylesheet" type="text/css" href="jplot/examples/examples.min.css" />
        <link type="text/css" rel="stylesheet" href="jplot/examples/syntaxhighlighter/styles/shCoreDefault.min.css" />
        <link type="text/css" rel="stylesheet" href="jplot/examples/syntaxhighlighter/styles/shThemejqPlot.min.css" />
		
	<!--== BEGIN SCRIPTS ==-->
	<script type="text/javascript" src="js/jquery.js"></script><!--JQuery Library-->
	<script type="text/javascript" src="js/jquery.preloadify.js"></script><!--Preloadify-->
	<script type="text/javascript" src="js/scripts-top.js"></script><!--General scripts header-->
	
	<!--[if IE]> <script type="text/javascript" src="js/html5.js"></script> <![endif]-->
	
	<!-- SWitcher -->
	<link rel="stylesheet" href="QSswitcher/switcher.css" />
	
</head>
<body>
<section id="main_template" class="layout_boxed clearfix">
<!-- ============================================================================================
**************************************** HEADER SECTION *****************************************
============================================================================================= -->
<section class="container_header clearfix">
	<div class="container_12 clearfix">
	
		<div class="grid_12 head_part clearfix">
			<?php require('logo.php'); ?>			
			<div class="pull-right hp_bg head_search clearfix">
				<form method="get" id="searchform" action="#">
					<input type="text" class="field" name="s" id="s" placeholder="Search" />
					<input type="submit" class="submit" name="submit" id="searchsubmit" value="" />
				</form>
			</div>
			
		</div><!-- End / .cleafix -->
		
		<div class="clear"></div>
		
	</div><!-- end / .container_12 -->
	
	<?php require('menu.php'); ?><!-- end / .main_menu_place -->	
	
</section><!-- end / .container_header -->


<!-- NULL SECTION
============================================================================================= -->
<section class="container_null">
	<div class="container_12 clearfix">
		<div class="grid_12 page_title clearfix">
			<h1 class="pull-left">Laporan Kehadiran Kursus</h1>
		</div>
	</div><!-- end / .container_12 -->
</section><!-- end / .container_header -->


<!-- ============================================================================================
**************************************** MIDDLE SECTION *****************************************
============================================================================================= -->
<section class="container_middle clearfix">
	<div class="container_12 clearfix">
		<div class="table table-bordered table-hover">
                    <form method="post">
<!--                        <div class="ui-widget">-->
                            <p><span>Jabatan</span>
                            <input type="text" name="jabatan" id="jabatan" value="<?php echo @$jabatan;?>"/></p>
                            <p><span>Tarikh</span>
                             dari <input type="text" name="tarikh_mula" id="tarikh_mula" /> 
                            hingga <input type="text" name="tarikh_tamat" id="tarikh_tamat" /></p>
                            <p><input type="submit" id="cari" name="cari" value="Cari" class="button"/></p>
                            
<!--                        </div>-->
                    </form>
                    <h3><?php echo $tajukRep?></h3>
                    <div id="chart1" style="height:300px; width:500px;"></div>

</div><!-- end / .container_12 -->
</section><!-- end / .container_middle -->
<?php require('footer.php'); ?>

<!-- SWitcher -->
<script type="text/javascript" src="QSswitcher/switcher.js"></script></div><!-- end / .container_12 -->

<!--Jquery & ui-->
<script type="text/javascript" src="js/jquery.js"></script><!--JQuery Library-->
<script type="text/javascript" src="../jquery/jquery-ui-1.10.0.custom.min.js"></script><!--UI-->
<link href="../css/jquery-ui-1.10.0.custom.css" rel="stylesheet" />

<!--- JqPlot tuk chart -->
<script class="include" type="text/javascript" src="jplot/jquery.jqplot.min.js"></script>
<script type="text/javascript" src="jplot/examples/syntaxhighlighter/scripts/shCore.min.js"></script>
<script type="text/javascript" src="jplot/examples/syntaxhighlighter/scripts/shBrushJScript.min.js"></script>
<script type="text/javascript" src="jplot/examples/syntaxhighlighter/scripts/shBrushXml.min.js"></script>

<!-- Additional plugins go here -->
<script class="include" type="text/javascript" src="jplot/plugins/jqplot.barRenderer.min.js"></script>
<script class="include" language="javascript" type="text/javascript" src="jplot/plugins/jqplot.pieRenderer.min.js"></script>
<script class="include" language="javascript" type="text/javascript" src="jplot/plugins/jqplot.donutRenderer.min.js"></script>

<!-- End additional plugins -->
<script type="text/javascript" src="jplot/examples/example.min.js"></script>

<script type="text/javascript" >
$(function(){
    $( "#tarikh_mula" ).click(function(){
        //alert('popo');
    })
    $( "#tarikh_mula" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      changeYear: true,
      numberOfMonths: 3,
      onClose: function( selectedDate ) {
        $( "#tarikh_tamat" ).datepicker( "option", "minDate", selectedDate );
      }
    });
    $( "#tarikh_tamat" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      changeYear: true,
      numberOfMonths: 3,
      onClose: function( selectedDate ) {
        $( "#tarikh_mula" ).datepicker( "option", "maxDate", selectedDate );
      }
    });
    
    //pie chart
    var data = [
    ['Lebih Dari 7 Hari', <?php echo $lebihsama7;?>],
    ['Kurang dari 7 hari', <?php echo $kurang7;?>]
    ,['Tidak menghadiri kursus', <?php echo $xp;?>]
  ];
  var plot1 = jQuery.jqplot ('chart1', [data],
    {
      seriesDefaults: {
        // Make this a pie chart.
        renderer: jQuery.jqplot.PieRenderer,
        rendererOptions: {
          // Put data labels on the pie slices.
          // By default, labels show the percentage of the slice.
          showDataLabels: true
        }
      },
      legend: { show:true, location: 'e' }
    }
  );
  
  
  //autocomplete jabatan
    var cache = {};
    $( "#jabatan" ).autocomplete({
        minLength: 2,
        source: function( request, response ) {
            var term = request.term;
            if ( term in cache ) {
                response( cache[ term ] );
                return;
            }
            $.getJSON( "jsonJabatan.php", request, function( data, status, xhr ) {
                cache[ term ] = data;
                response( data );
            });
        }
    });
})
</script>
 <style>
.ui-autocomplete {
max-height: 100px;
overflow-y: auto;
/* prevent horizontal scrollbar */
overflow-x: hidden;
}
/* IE 6 doesn't support max-height
* we use height instead, but this forces the menu to always be this tall
*/
* html .ui-autocomplete {
height: 100px;
}
</style>
</section><!-- end / #main_template -->
<script type="text/javascript" src="js/bootstrap.js"></script><!--BootStrap-->
<script type="text/javascript" src="js/jquery.plugins.js"></script><!--Plugins-->
<script type="text/javascript" src="js/prettyphoto/js/jquery.prettyPhoto.js"></script><!--Plugins-->
<script type="text/javascript" src="js/mediaelement/lib/mediaelement.js"></script>
<script type="text/javascript" src="js/mediaelement/lib/mediaelementplayer.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js@sensor=false"></script><!-- Google Map API -->
<script type="text/javascript" src="js/gmap3.min.js"></script><!--Google map plugin-->
<script type="text/javascript" src="js/gmap.init.js"></script><!--Google map init-->
<script type="text/javascript" src="js/scripts-bottom.js"></script><!--Scripts-->
<script type="text/javascript" src="js/demo-scripts.js"></script><!--Demo-->
</body>
</html>
